package com.cskaoyan.service.impl;

import com.cskaoyan.bean.pojo.MallUser;
import com.cskaoyan.bean.vo.UserIndexOuterVO;
import com.cskaoyan.bean.vo.UserIndexVO;
import com.cskaoyan.mapper.MallCollectMapper;
import com.cskaoyan.mapper.MallOrderGoodsMapper;
import com.cskaoyan.mapper.MallOrderMapper;
import com.cskaoyan.service.WxUserIndexService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: Chunlai
 * @description:
 * @time: 2021/7/11 21:25
 */
@Service
public class WxUserIndexServiceImpl implements WxUserIndexService {

    @Autowired
    MallOrderMapper mallOrderMapper;

    @Autowired
    MallOrderGoodsMapper mallOrderGoodsMapper;

    @Override
    public UserIndexOuterVO queryordercount() {

        Subject subject = SecurityUtils.getSubject();
        MallUser mallUser = (MallUser) subject.getPrincipal();
        Integer id = mallUser.getId();


        //待收货 - 1 参数
        int unrecv = mallOrderMapper.selectorderstatus301(id);
        //未评价 - 2 参数
        //int uncomment = mallOrderMapper.selectorderstatus401(id);


        List<Integer> comments = mallOrderMapper.selectorderstatus401Byfengyi(id);
        int uncomment = 0;
        for (Integer comment : comments) {
            uncomment += comment;
        }
        //未付款 - 3 参数
        int unpaid = mallOrderMapper.selectorderstatus101(id);
        //未发货 -4 参数
        int unship = mallOrderMapper.selectorderstatus201(id);

//        if (uncomment != 0 ){ // 说明我们存在已收货的订单
//            Integer amount_uncomment_sn = 0 ;   //未评论的数量
//            //todo 对已收货的订单进行获取，看订单是否被评论，并统计个数
//            List<Integer> commentsn = mallOrderMapper.selectbyUncomment(id);
//            for (Integer ids : commentsn) {
//                int index = mallOrderGoodsMapper.selectBycommentsn(ids);
//                if (index == 1){
//                    amount_uncomment_sn += 1;
//                }
//            }
//            uncomment = amount_uncomment_sn;
//        }

        UserIndexVO userIndexVO = new UserIndexVO(unrecv,uncomment,unpaid,unship);
        UserIndexOuterVO userIndexOuterVO = new UserIndexOuterVO(userIndexVO);
        return userIndexOuterVO;
    }
}